<?php

namespace Framework;

/**
 * Session
 *
 * @author  Jason Napolitano <jason@jasonnapolitano.com>
 * @version 2.0.0
 * @package Framework
 */

class Session
{
    /**
     * Start the session
     *
     * @access public
     * @return void
     */
    public static function start()
    {
        if (session_status() == PHP_SESSION_NONE){
            # code...
            session_start();
        }
    }

    /**
     * Set a session variable
     *
     * @access public
     * @param string $key   The key to set
     * @param string $value The value to set
     * @return void
     */
    public static function set($key, $value)
    {
        $_SESSION[$key] = $value;
    }

    /**
     * Get a session variable
     *
     * @access public
     * @param string $key The key to get
     * @return mixed
     */
    public static function get($key,$default=null)
    {
        return isset($_SESSION[$key]) ? $_SESSION[$key] : $default;
    }

    public static function has($key){
        return isset($_SESSION[$key]);
    }

    public static function clear($key){
        if (isset($_SESSION[$key])) {
            # code...
            unset($_SESSION[$key]);
        }
    }

    public static function clearAll(){
        session_unset();
        session_destroy();
    }

    public static function setFlashMessage($key, $message){
        self::set('flash_' . $key, $message);
    }

    public static function getFlashMessage($key,$default = null){
        $message = self::get('flash_' . $key,$default);
        self::clear('flash_' . $key);
        return $message;
    }

}

?>